home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
libgutil
/
handline.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
153 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* handline -
* Human line code follows
*
* Paul Haeberli - 1991
*/
#include "vect.h"
static humanline();
static distort();
float fnoise3();
float frand();
#define NMULTI (1)
#define MAGMULTI (0.05)
#define TOLERANCE (0.000001)
static float wobfreq = 1.0;
static float wobmag = 0.0;
static float warpfreq = 1.0;
static float warpmag = 0.0;
static float seglen = 0.2;
static float dropout = 0.2;
static float humanoffsets[NMULTI];
handsetwobble(freq,mag)
float freq, mag;
{
wobfreq = freq;
wobmag = mag;
}
handsetwarp(freq,mag)
float freq, mag;
{
warpfreq = freq;
warpmag = mag;
}
handsetseglen(len)
float len;
{
seglen = len;
}
handsetdropout(val)
float val;
{
dropout = val;
}
handline(linefunc,v1,v2)
int (*linefunc)();
vect *v1, *v2;
{
int i;
float len, temp;
vect del, sdel, p1, p2;
vsub(v2,v1,&del);
len = vlength(&del);
if(len<TOLERANCE)
return;
vscale(&del,1.0/len);
for(i=0; i<NMULTI; i++) {
sdel = del;
vscale(&sdel,MAGMULTI*humanoffsets[i]);
temp = sdel.x;
sdel.x = -sdel.y;
sdel.y = temp;
vadd(v1,&sdel,&p1);
vadd(v2,&sdel,&p2);
humanline(linefunc,&p1,&p2,0.0);
}
}
handdown()
{
int i;
for(i=0; i<NMULTI; i++) {
/* humanoffsets[i] = frand()-0.5; */
humanoffsets[i] = 0.0;
}
}
static humanline(linefunc,v1,v2,offset)
int (*linefunc)();
vect *v1, *v2;
float offset;
{
int i, nsegs;
vect delta, p1, p2, d1, d2;
float len;
vsub(v2,v1,&delta);
len = vlength(&delta);
nsegs = (len/seglen)+1;
vscale(&delta,1.0/nsegs);
p1 = *v1;
for(i=0; i<nsegs; i++) {
vadd(&p1,&delta,&p2);
distort(&p1,&d1,offset);
distort(&p2,&d2,offset);
if(frand()>=dropout) {
linefunc(&d1,&d2);
}
p1 = p2;
}
}
static distort(v1,v2,offset)
vect *v1, *v2;
float offset;
{
float dx, dy, cx, cy;
cx = v1->x;
cy = v1->y;
if(warpmag>0.0) {
dx = warpmag*fnoise3(0.3*offset+0.0+warpfreq*v1->x,warpfreq*v1->y,0.0);
dy = warpmag*fnoise3(0.3*offset+5.0+warpfreq*v1->x,warpfreq*v1->y,0.0);
cx += dx;
cy += dy;
}
if(wobmag>0.0) {
dx = wobmag*fnoise3(0.3*offset+0.0+wobfreq*v1->x,wobfreq*v1->y,0.0);
dy = wobmag*fnoise3(0.3*offset+5.0+wobfreq*v1->x,wobfreq*v1->y,0.0);
cx += dx;
cy += dy;
}
v2->x = cx;
v2->y = cy;
}